<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../config/config.php";
require_once "../model/adminDb.php";

error_reporting(E_ERROR);
ini_set("display_errors","Off");
$adminDb = new adminDb();
$data = $_POST['data'];
$id = $_POST['id'];
$content=$data['content'];
$platfrom = $_POST['platfrom'];
$product = $data['product'];
$person = $data['person'];
$title = $data['title'];
$desc = $data['desc'];
$url = $_POST['imgUrl'];
$newName = $data['new_name'];
$addtime = time();
$status = 0;
//查询旧bug的image
$preData=$adminDb->queryBug_id($id);
$preImage=$preData[0]['image'];

$preImage=trim($preImage,"\"[]");

$preImage=explode(",",$preImage);
$root = dirname(dirname(__FILE__));


$addData = $adminDb->edit_bug($id, $product, $platfrom, $person, $title, $desc,$content, $url, $newName, $status, $addtime);

try {

    if ($addData) {

        for($i=0;$i<count($preImage);$i++){
            $charimg=trim(strchr($preImage[$i],'..'),'..');
            $charimg=$root.$charimg;
            $result=unlink($charimg);

        }

        $dat = array(
            'message' => "编辑成功",
            "code" => 200,

        );
        echo json_encode($dat);
    } else {
        $dat = array(
            "code" => 404,
            'message' => "保存失败",

        );
        echo json_encode($dat);

    }
} catch (Exception $e) {

    // 回滚事务
    // $pdo->rollback();
    echo $e->getMessage();
}













